﻿@{
    ViewBag.Title = "Action_List";
    Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
@section head
{
    <link href="@Url.Content("~/Content/zTreeStyle/zTreeStyle.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery.ztree.all-3.0.min.js")" type="text/javascript"></script>
    @Html.Partial("_JqGrid")
    <script language="javascript" type="text/javascript">
        var selectId = "";
        var ActionId = "";
        var selectrow = 1; //选中的行，默认为1
        var gridId = "#tableId";
        var curSelectNode = null;
        $(document).ready(function () {
            loadBaseDicTree('/SystemManage/Menu/GetMenuTreeNode/', 'menu_id', 'meun_parentid', 'menu_name', true);
            funGridInit();

        });
        function zTreeOnClick(event, treeId, treeNode, clickFlag) {
            curSelectNode = treeNode;
            selectId = treeNode.menu_id;
             _zTreeObj.expandNode(treeNode, true); //展开点击节点
            $(gridId).trigger("reloadGrid");
        }
        function zTreeOnAsyncSuccess(event, treeId, treeNode, msg) {
            if (curSelectNode == null) {//如果加载完，没有选中节点，则默认选中第一个节点
                var nodes = _zTreeObj.getNodes();
                if (nodes.length > 0) {
                    _zTreeObj.selectNode(nodes[0]);
                    zTreeOnClick('', _zTreeObj, nodes[0], 1); //触发单击事件。
                }
            }
        }
        function ActionAdd(type) {
            //增加
            var u = "/ActionManager/Action/Action_Edit?MenuId=" + selectId;
            parent.asyncbox.open({
                url: u,
                data:type=='edit'? 'id=' + ActionId :"",
                title: "新增",
                width: 450,
                height: 260,
                scroll: 'no',
                modal: true,
                btnsbar: parent.$.btn.OKCANCEL, //按钮栏配置请参考 “辅助函数” 中的 $.btn。
                callback: function (action) {
                    var t = this;
                    if (action == 'ok') {
                        DialogFrame($(this).attr("id")).Save(t);
                        return false;

                    }
                    if (action == 'cancel') {
                    }
                    if (action == 'close') {
                    }
                }
            });
        }
        function ActionDelete() {
            //删除
            $.funListDelete(gridId, "ActionID", '@Url.Content("~/ActionManager/Action/DeleteAction")');

        }

        function showdialog() { }

        function refreshTreeNode(type) {
            var nodes = _zTreeObj.getSelectedNodes();
            if (nodes.length <= 0) return;
            if (type == "add") {
                nodes[0].isParent = true;
                _zTreeObj.reAsyncChildNodes(nodes[0], "refresh");
            }
            else {
                _zTreeObj.reAsyncChildNodes(nodes[0].getParentNode(), "refresh");
            }
        }
        function funGridInit() {
            //初始化表格
            var option = {
                height: $("#divGridContainer").height() - 51,
                width: $("#divGridContainer").width() - 2,
                url: '@Url.Content("~/ActionManager/Action/Action_GetList")',
                autowidth: false,
                datatype: "json",
                sortname: 'ActionID',
                sortorder: 'asc',
                colModel: [
                { label: '编号', name: 'ActionCode', width: 100 },
                { label: '名称', name: 'ActionName', width: 120 },
                { label: '所在菜单', name: 'Menu_NAME', width: 120 },
                { hidden: true, name: 'ActionID' },
                { hidden: true, name: 'MenuID' }
   	            ],
                onSelectRow: function (rowid, cellname, value, iRow, iCol) {
                    selectId = $(gridId).getCell(rowid, "MenuID");
                    ActionId = $(gridId).getCell(rowid, "ActionID");
                    selectrow = rowid;
                    // 同步树
                    curSelectNode = _zTreeObj.getNodeByParam("menu_id", selectId, null);
                    _zTreeObj.selectNode(curSelectNode);
                },
                ondblClickRow: function (rowid) {
                    if (rowid >= 0) {
                        selectId = $(gridId).getCell(rowid, "MenuID");
                        ActionId = $(gridId).getCell(rowid, "ActionID");
                        selectrow = rowid;
                        ActionAdd('edit');


                    }
                },
                beforeRequest: function (d) {
                     if (curSelectNode == null) return false;
                    var data = { menuid: curSelectNode == null ? '' : curSelectNode.menu_id };
                    $(gridId).jqGrid('setGridParam', { postData: data });
                },
                gridComplete: function () {

                }
            };
            var o = jqGridHelper.getConfig("#pageId", option);
            $(gridId).jqGrid(o);
        }
    </script>
}
<!--头部导航,不用时可以去掉-->
<div class="ui-layout-north">
    <div id="headertitle">
    </div>
    <div class="buttonlist" style="float: right; height: 34px; line-height: 36px; margin-right: 20px;">
        <a onclick="ActionAdd('add')" class="button green"><span class="icon-botton" style="background: url('/Content/16/add.png') no-repeat scroll 0px 4px;"> </span>新增</a> 
        <a onclick="ActionAdd('edit')" class="button green"><span class="icon-botton" style="background: url('/Content/16/edit.png') no-repeat scroll 0px 4px;"></span>编辑</a>
        <a onclick="ActionDelete()" class="button green"><span class="icon-botton" style="background: url('/Content/16/delete.png') no-repeat scroll 0px 4px;"></span>删除</a>
    </div>
</div>
<!--左侧导航，不用时直接去掉-->
<div class="ui-layout-west">
    @Html.Partial("_BaseDicTree")
</div>
<div id="divGridContainer" class="ui-layout-center" style="overflow: auto;">
    <table id="tableId">
    </table>
    <div id="pageId">
    </div>
</div>
<!--主窗体，页面都需要的div-->
<div class="ui-layout-center" style="overflow: auto;">
</div>
